layui.use(['layer'], function() {
    var layer = layui.layer;
    /*var localData = layui.data('blog');
    layer.alert(localData.token, {icon: 6});*/

    $(function() {//初始化页面加载
        getLoginInfo();
    });

    //获取登录信息
    function getLoginInfo() {
        $.ajax({
            url: '/user/getLoginInfo',
            type: 'POST',
            dataType: 'JSON',
            success: function(res) {
                if(res.code == '200') {
                    $('#js-login-info').text('欢迎光临，' + res.data.userName)
                }else {
                    location.href = '/admin/login.html';
                }
            },
            error: function(error) {
                layer.closeAll('loading');
            }
        });
    }



});


//退出登录
function loginOut() {
    $.ajax({
        url: '/user/outLogin',
        type: 'POST',
        dataType: 'JSON',
        success: function(res) {
            if(res.code == '200') {
                location.href = "/admin/login.html";
            }
        },
        error: function(error) {
        }
    });
}


/**
 * 查询分类
 */
function queryType() {
    $.ajax({
        type: 'POST',
        url: '/blog/queryBlogType',
        dataType: 'json',
        contentType: 'application/json; charset=UTF-8',// 解决415错误
        success: function (res) {
            if('200' == res.code) {
                var typeHtml = '';
                var typeData = res.data;
                $.each(typeData,function (index,val) {
                    if(index == 0) {
                        typeHtml += '<input type="radio" name="typeId" value="'+val.typeId+'" title="'+val.typeName+'" checked="">';
                    }else {
                        typeHtml += '<input type="radio" name="typeId" value="'+val.typeId+'" title="'+val.typeName+'">';
                    }
                });
                $('#js-blog-typeId').html(typeHtml);
            }
        }
    });
}

/**
 * 查询标签
 */
function queryTag() {
    $.ajax({
        type: 'POST',
        url: '/blog/queryBlogTag',
        dataType: 'json',
        contentType: 'application/json; charset=UTF-8',// 解决415错误
        success: function (res) {
            if('200' == res.code) {
                var tagHtml = '';
                var tagData = res.data;
                $.each(tagData,function (index,val) {
                    tagHtml += '<input type="checkbox" lay-verify="required"  name="blogTag" value="'+val.tagId+'" title="'+val.tagName+'">';
                });
                $('#js-blog-tagId').html(tagHtml);
            }
        }
    });
}




